package jhr.cms.action;

import java.util.Date;

import jhr.cms.domain.ServiceException;
import jhr.cms.domain.User;
import jhr.cms.service.UserServiceIF;
import jhr.cms.utils.StringUtils;

public class UserAction extends BaseAction {
	private UserServiceIF userService;
	public void setUserService(UserServiceIF userService) {
		this.userService = userService;
	}
	
	/**
	 * 用户注册
	 * @author i5i2@163.com
	 * @since 2012-3-18 下午4:15:38
	 * @return
	 */
	public String register(){
		String userName = request.getParameter("userName");
		String password = request.getParameter("password");
		String email = request.getParameter("email");
		try{
			if(!StringUtils.hasLength(userName, password))
				throw new ServiceException("用户名和密码不能为空！");
			User user = new User();
			user.setEmail(email);
			user.setName(userName);
			user.setPassword(password);
			user.setRegTime(new Date());
			userService.save(user);
			this.setTip(true);
			this.setObj(user);
		}catch (Exception e) {
			e.printStackTrace();
			this.setTip(false);
			this.setErrorStr(e.getMessage());
		}
		return SUCCESS;
	}
}
